package com.yq.bootrabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName AmqpConfig
 * @Description TODO
 * @Author yaoqiang
 * @Date 2021/11/1 17:04
 * @Version 1.0
 */
@Configuration
public class AmqpConfig {
    @Bean
    public TopicExchange topicExchange(){
        return  new TopicExchange("BootTopicExchange");
    }

    @Bean
    public Queue topicQueue(){
        return new Queue("topicQueue");
    }

    @Bean
    public Queue topicQueue2(){
        return new Queue("topicQueue2");
    }

    @Bean
    public Binding topicBinding(Queue topicQueue,TopicExchange topicExchange){
        return  BindingBuilder.bind(topicQueue).to(topicExchange).with("Boot.#");
    }
    @Bean
    public Binding topicBinding2(Queue topicQueue2,TopicExchange topicExchange){
        return  BindingBuilder.bind(topicQueue2).to(topicExchange).with("*.txt");
    }


    @Bean
    public DirectExchange myExchange(){
        return new DirectExchange("BootDirectExchange");
    }
    @Bean
    public Queue queue(){
        return new Queue("myQueueDirect");
    }

    /***
     *
     * @param queue 自定义队列对象，参数名为queue为自定义队列bean的id
     * @param myExchange 自定义的交换机，参数名为myChange为自定义交换机bean的id
     * @return
     */
    @Bean("binding")
    public Binding binding(Queue queue, Exchange myExchange){
        //将队列和交换机绑定，参数BootRouting为RoutingKey
        return BindingBuilder.bind(queue).to(myExchange).with("BootRouting").noargs();
    }

    @Bean
    public FanoutExchange fanoutExchange(){
        return  new FanoutExchange("BootFanoutExchange");
    }

    @Bean
    public Queue fanoutQueue(){
        return new Queue("fanoutQueue");
    }

    @Bean
    public Binding fanoutBinding(Queue fanoutQueue,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutQueue).to(fanoutExchange);
    }


}
